package com.goodlearning.gloriamobile.commons;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
/**
 * WebView 추가 구현 없이 여기서 가져다 쓴다.
 * @author rapty54
 *
 */
public class WebClientManager extends WebViewClient {

	Context context;

	ProgressBar progressBar;

	WebView webView;
	
	int Count;
	
	public WebClientManager(Context context, ProgressBar progressBar,WebView webView,int Count) {
		this.context = context;
		this.progressBar = progressBar;
		this.webView = webView;
		this.Count=Count;
		progressBar.setVisibility(View.VISIBLE);
	}
	
	@Override
	public void onPageStarted(WebView view, String url, Bitmap favicon) {

		super.onPageStarted(view, url, favicon);
	}
	
	@Override
	public void onPageFinished(WebView view, String url) {
		view.setVisibility(View.VISIBLE);
		webView.clearHistory();
		progressBar.setVisibility(View.INVISIBLE);
		
		if(Count==1){
			Toast.makeText(context, "화면 보기 축소 확대가 가능합니다.", Toast.LENGTH_SHORT).show();
		}
	}
	
	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		view.loadUrl(url);
		return true;
	}

	class WebChromeCustomClient extends android.webkit.WebChromeClient {
		
		@Override
		public void onProgressChanged(WebView view, int newProgress) {
			if (newProgress <= 99) {
				progressBar.setVisibility(View.VISIBLE);
			} else {
				progressBar.setVisibility(View.INVISIBLE);
			}
			
		}
	}
}
